﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Xml;

namespace SPWebShell.entity
{
    /// <summary>
    /// Represents information about a List or a document library
    /// </summary>
    [DebuggerDisplay("Title={Title}")]
    public class SPList
    {
        Dictionary<string, string> _namevalues;
        XmlNode _node;
        public SPList(XmlNode ndList)
        {
            _namevalues = new Dictionary<string, string>();
            _node = ndList;
            foreach (XmlAttribute attr in ndList.Attributes)
            {
                _namevalues.Add(attr.Name, attr.Value);
            }
        }
        /// <summary>
        /// The title of the list. Web services will use this parameter.
        /// </summary>
        public string Title 
        {
            get
            {
                return _namevalues["Title"];
            }
        }
        public string DefaultViewUrl
        {
            get
            {
                return _namevalues["DefaultViewUrl"];
            }
        }
        /// <summary>
        /// The internal unique ID of the list
        /// </summary>
        public Guid ID
        {
            get
            {
                return  new Guid (_namevalues["ID"]);
            }
        }
        public int ItemCount 
        { 
            get
            {
                return Int32.Parse(_namevalues["ItemCount"]);
            }
        }
        public bool Versioning 
        { 
            get
            {
                return Boolean.Parse(_namevalues["EnableVersioning"]);
            }
        }
        /// <summary>
        /// All fields in the List.
        /// </summary>
        public entity.SPField[] Fields;
        public override string ToString()
        {
            if (_node != null)
            {
                return _node.OuterXml;
            }
            else
            {
                return "";
            }
        }
        public Dictionary<string, string> NameValues 
            {
                get
                {
                    return _namevalues;
                }
            }
    }
}
